home *** CD-ROM | disk | FTP | other *** search
- /*==================================================================
- File: ZString.h
-
- Contains: Class for handling "z strings", a hieararchical
- dictionary of strings for cross-platform and
- localization purposes.
-
- Written by: Eric Traut
-
- Copyright: 2000-2001 Connectix Corporation
-
- This source has been placed into the public domain by
- Connectix Corporation. You have the right to modify,
- distribute or use this code without any legal limitations
- or finanicial/licensing requirements. Connectix is not
- liable for any problems that result from the use of this
- code.
-
- If you have comments, feedback, questions, or would like
- to submit bug fixes or updates to this code, please email
- opensource@connectix.com.
- ==================================================================*/
-
- #ifndef __ZSTRING__
- #define __ZSTRING__
-
-
- #include "ZStringData.h"
-
- #include <string.h>
-
- enum
- {
- // We'll start the IDs at 128 because of the Mac platform,
- // which defines resource numbers below 128 as "owned by
- // the system".
-
- kEnglishOverrideID = 128,
- kGermanOverrideID = 129,
- kFrenchOverrideID = 130,
- kJapaneseOverrideID = 131,
- kItalianOverrideID = 132,
- kSpanishOverrideID = 133,
- kPortugueseOverrideID = 134
-
- // Add more languages as necessary...
- };
-
-
- /*==================================================================
- ZString
- ==================================================================*/
-
- class ZString
- {
- public:
- // Construction & Destruction
- ZString()
- {
- mData = NULL;
- }
-
- ZString(
- ZString & inString)
- {
- mData = inString.GetData();
- if (mData != NULL)
- mData->IncrementRefCount();
- }
-
- ZString(
- const char * inString);
-
- ~ZString()
- {
- ReleaseData();
- }
-
- // Loading "named strings"
- void
- GetNamedString(
- const char * inNamedString,
- Z_Boolean inDataIsVolatile = false);
-
- static ZString
- GetNamedZString(
- const char * inNamedString,
- Z_Boolean inDataIsVolatile = false);
-
- static void
- PopulateDictionary(
- const char * inOverrideDict,
- Z_Boolean inDataIsVolatile = false);
-
- // Accessing String Length
- Z_UInt16
- GetLength() const
- {
- if (mData == NULL)
- return 0;
- else
- return (Z_UInt16)mData->GetLength();
- }
-
- // Accessing String
- const char *
- GetCString() const
- {
- if (mData == NULL)
- return "";
- else
- return mData->GetStringData();
- }
-
- // Extracting String
- Z_UInt16
- GetCString(
- char * outString,
- Z_UInt16 inBufferSize);
-
- Z_UInt8
- GetPString(
- Z_UInt8 * outString,
- Z_UInt16 inBufferSize = 256);
-
- ZString
- GetSubstring(
- Z_UInt16 inIndex,
- char inSeparator);
-
- // Setting the String
- void
- SetString(
- const char * inString,
- Z_UInt16 inLength);
-
- void
- SetCString(
- const char * inString);
-
- void
- SetPString(
- const Z_UInt8 * inString);
-
- // Assigning String to New String
- ZString
- operator = (
- ZString & inString);
-
- ZString
- operator = (
- const char * inString)
- {
- SetCString(inString);
-
- return *this;
- }
-
- // Appending Strings
- ZString &
- operator += (
- const ZString & inString)
- {
- ConcatString(inString, inString.GetLength());
- return *this;
- }
-
- ZString &
- operator += (
- char inChar)
- {
- ConcatString(&inChar, 1);
- return *this;
- }
-
- ZString &
- operator += (
- const char * inString)
- {
- ConcatString(inString, strlen(inString));
- return *this;
- }
-
- ZString
- operator + (
- const ZString & inString)
- {
- ZString newString;
- newString.ConcatStrings(GetCString(), GetLength(), inString.GetCString(), inString.GetLength());
- return newString;
- }
-
- friend ZString
- operator + (
- const ZString & inStringA,
- const char * inStringB)
- {
- ZString newString;
- newString.ConcatStrings(inStringA, inStringA.GetLength(), inStringB, strlen(inStringB));
- return newString;
- }
-
- friend ZString
- operator + (
- const char * inStringA,
- ZString & inStringB)
- {
- ZString newString;
- newString.ConcatStrings(inStringA, strlen(inStringA), inStringB, inStringB.GetLength());
- return newString;
- }
-
- friend ZString
- operator + (
- ZString & inStringA,
- ZString & inStringB)
- {
- ZString newString;
- newString.ConcatStrings(inStringA, inStringB.GetLength(), inStringB, inStringB.GetLength());
- return newString;
- }
-
- // Replacing Substrings
- ZString
- ReplaceParameter(
- Z_UInt8 inParamNum,
- const char * inString);
-
- ZString
- ReplaceParameter(
- Z_UInt8 inParamNum,
- Z_SInt32 inNumber);
-
- // Casting
- operator const char *() const
- {
- return GetCString();
- }
-
- // Low-level Manipulation
- ZStringData *
- GetData()
- {
- return mData;
- }
-
- void
- AllocateData(
- Z_UInt32 inStringLength);
-
- void
- ReleaseData()
- {
- if (mData != NULL)
- {
- mData->DecrementRefCount();
- mData = NULL;
- }
- }
-
- private:
- void
- FillInString(
- const char * inString,
- Z_UInt16 inOffset,
- Z_UInt16 inLength)
- {
- if (mData != NULL)
- mData->FillInString(inString, inOffset, inLength);
- }
-
- void
- ConcatStrings(
- const char * inStringA,
- Z_UInt16 inStringALen,
- const char * inStringB,
- Z_UInt16 inStringBLen);
-
- void
- ConcatString(
- const char * inString,
- Z_UInt16 inStringLen);
-
- ZStringData * mData;
- };
-
-
- #endif // __ZSTRING__
-
-
-